﻿
#include "zyTabControl.h"

BlackMoonUI::zyTabControl::zyTabControl()
{
	SetMember(L"this", (LONG_PTR)this);
	m_obj->setWndProc(zyTabControl_WndProc);
	m_obj->setChildWndProc(zyTabControl_ChildWndProc);
	m_obj->setDestroy(zyTabControl_Destroy);
	std::unordered_map<LPARAM, std::wstring>* Controls = new std::unordered_map<LPARAM, std::wstring>();
	SetMember(L"HashToolTips", (LONG_PTR)Controls);
	setType(zyType_TabControl);
}
BlackMoonUI::zyTabControl::~zyTabControl()
{

}
void WINAPI BlackMoonUI::zyTabControl::zyTabControl_Destroy(zyObject* obj)
{
	zyTabControl* zyb = (zyTabControl*)obj->getPtrData(L"this");
	zyb->OnNCDestroy();
	zyCustomCtrol::zyCustomCtrol_Destroy(obj);
}
LRESULT WINAPI BlackMoonUI::zyTabControl::zyTabControl_ChildWndProc(zyObject* obj, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandle)
{
	if (uMsg == WM_NOTIFY) {
		NMHDR* nm = (NMHDR*)lParam;
		if (nm->code == TCN_SELCHANGE) {
			zyTabControl* zyb = (zyTabControl*)obj->getPtrData(L"this");
			zyb->ShowPanel(nm->hwndFrom, (int)SendMessage(nm->hwndFrom, TCM_GETCURSEL, 0, 0));
			TRegEvent* evtPtr = (TRegEvent*)obj->getRegEvent(L"OnSelChange");
			if (evtPtr != nullptr)
				evtPtr->handler<int>(nm->hwndFrom);
		}
		else if (nm->code == TCN_SELCHANGING) {
			TRegEvent* evtPtr = (TRegEvent*)obj->getRegEvent(L"OnSelChanging");
			if (evtPtr != nullptr) {
				int ret = evtPtr->handler<int>(nm->hwndFrom);
				if (ret) {
					*bHandle = true;
					return 1;
				}
			}
		}
		else if (nm->code == NM_CLICK) {
			TRegEvent* evtPtr = (TRegEvent*)obj->getRegEvent(L"OnClick");
			if (evtPtr != nullptr)
				evtPtr->handler<int>(nm->hwndFrom);
		}
		else if (nm->code == NM_RCLICK) {
			TRegEvent* evtPtr = (TRegEvent*)obj->getRegEvent(L"OnRClick");
			if (evtPtr != nullptr) {
				evtPtr->handler<int>(nm->hwndFrom);
				*bHandle = true;
				return 1;
			}
		}
		else if (nm->code == TTN_NEEDTEXTW) {
			void* HashToolTips = obj->getPtrData(L"HashToolTips");
			if (HashToolTips != nullptr) {
				NMTTDISPINFO* ttinfo = reinterpret_cast<NMTTDISPINFO*>(lParam);
				TCITEM tci = { 0 };
				tci.mask = TCIF_PARAM;
				SendMessage(hWnd, TCM_GETITEMW, ttinfo->hdr.idFrom, (LPARAM)&tci);
				std::unordered_map<LPARAM, std::wstring>* ToolTips = static_cast<std::unordered_map<LPARAM, std::wstring>*>(HashToolTips);
				auto it = ToolTips->find(tci.lParam);
				if (it != ToolTips->end()) {
					//ToolTips->erase(it);
					//wchar_t* text(new wchar_t[it->second.size() + 1]);
					//wcscpy_s(text, it->second.size() + 1, it->second.c_str());
					ttinfo->lpszText = (LPWSTR)it->second.c_str();
					//std::wstring text = it->second;
					//ttinfo->lpszText = (LPWSTR)text.c_str();
				}
			}
		}
	}
	return zyCtrol::zyCtrol_ChildWndProc(obj, hWnd, uMsg, wParam, lParam, bHandle);
}
LRESULT WINAPI BlackMoonUI::zyTabControl::zyTabControl_WndProc(zyObject* obj, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandle)
{
	if (uMsg == WM_NCDESTROY) {
		zyTabControl* zyb = (zyTabControl*)obj->getPtrData(L"this");
		zyb->OnNCDestroy();
	}
	else if (uMsg == WM_SIZE) {
		zyTabControl* zyb = (zyTabControl*)obj->getPtrData(L"this");
		zyb->SetPanelsSize(hWnd);
	}
	else if (uMsg == WM_DESTROY) {
		zyTabControl* zyb = (zyTabControl*)obj->getPtrData(L"this");
		zyb->DeleteAllPanel(hWnd);
	}
	return zyCustomCtrol::zyCustomCtrol_WndProc(obj, hWnd, uMsg, wParam, lParam, bHandle);
}

void BlackMoonUI::zyTabControl::OnNCDestroy() {
	LONG_PTR HashToolTips = GetMember(L"HashToolTips");
	if (HashToolTips != 0) {
		std::unordered_map<LPARAM, std::wstring>* ToolTips = (std::unordered_map<LPARAM, std::wstring>*)HashToolTips;
		if (ToolTips != nullptr) {
			ToolTips->clear();
			delete ToolTips;
		}		
		SetMember(L"HashToolTips", 0);
	}

	resObject* pImageList = (resObject*)GetMember(L"pImageList");
	if (pImageList != nullptr) {
		pImageList->release();
		SetMember(L"pImageList", 0);
	}
	RECT* ExtendRext = (RECT*)GetMember(L"ExtendRext");
	if (ExtendRext != nullptr) {
		delete ExtendRext;
        SetMember(L"ExtendRext", 0);
	}
}
// 函数声明，检查宽字符串 data 中是否包含 searchString  
bool BlackMoonUI::zyTabControl::ContainsString(const WCHAR* data, const WCHAR* searchString) {
	// 注意：虽然你提供了 dataSize 参数，但 wcsstr 并不会使用它。  
	// 如果你需要基于长度来限制搜索，你需要自己实现这部分逻辑。  
	// 但对于标准的 wcsstr 调用，我们只需要确保 data 和 searchString 是有效的。  

	// 检查 data 和 searchString 是否非空  
	if (data == nullptr || searchString == nullptr) {
		return false; // 如果任一参数为空，则不包含  
	}

	// 使用 wcsstr 搜索 searchString 在 data 中的位置  
	// 如果找到，wcsstr 返回指向首次出现的指针；否则返回 nullptr  
	return wcsstr(data, searchString) != nullptr;
}
bool BlackMoonUI::zyTabControl::LoadAndCheckManifest(HINSTANCE hInstance) {
	HRSRC hRes = FindResource(hInstance, MAKEINTRESOURCE(1), RT_MANIFEST);
	if (hRes == nullptr) {
		return false;
	}

	HGLOBAL hGlobal = LoadResource(hInstance, hRes);
	if (hGlobal == nullptr) {
		return false;
	}

	DWORD dataSize = SizeofResource(hInstance, hRes);
	if (dataSize == 0 || dataSize > 4096) {//MAX_BUFFER_SIZE
		return false;
	}

	const void* pData = LockResource(hGlobal);
	if (pData == nullptr) {
		return false;
	}

	const WCHAR* pDataStr = static_cast<const WCHAR*>(pData);
	if (ContainsString(pDataStr, L"name=\"Microsoft.Windows.Common-Controls\" version=\"6.0.0.0\"")) {
		return true;
	}
	else {
		return false;
	}
}
void BlackMoonUI::zyTabControl::ShowPanel(HWND hWndTab, int index)
{
	int count = (int)SendMessage(hWndTab, TCM_GETITEMCOUNT, 0, 0);
	TCITEM tci = {0};
	//tci.cbSize = sizeof(TCITEM);
	tci.mask = TCIF_PARAM;
	for (int i = 0; i < count; i++) {
		tci.lParam = 0;
		SendMessage(hWndTab, TCM_GETITEMW, i, (LPARAM)&tci);
		zyWindow* panel = reinterpret_cast<zyWindow*>(tci.lParam);
		if (panel != nullptr) {
			HWND hwndPanel = (HWND)panel->GetMember(L"hWnd");

			if (i == index)
				ShowWindow(hwndPanel, SW_SHOW);
			else
				ShowWindow(hwndPanel, SW_HIDE);
		}
	}
}
void BlackMoonUI::zyTabControl::SetPanelSize(HWND hWndTab, LPARAM Panel)
{
	int lastIndex = (int)SendMessage(hWndTab, TCM_GETITEMCOUNT, 0, 0);
	if (lastIndex == -1 || Panel == 0)
		return;
	zyWindow* pane = reinterpret_cast<zyWindow*>(Panel);
	if (!pane) return;
	HWND hWnd = (HWND)pane->GetMember(L"hWnd");
	if (!hWnd || !IsWindow(hWnd)) return; // 关键检查
	LONG_PTR HideSelf = GetMember(L"HideSelf");
	RECT tabRect, panelRect;
	GetClientRect(hWndTab, &tabRect);
	if (HideSelf != 0) {
		panelRect = tabRect;
		MoveWindow(hWnd, panelRect.left, panelRect.top, panelRect.right - panelRect.left, panelRect.bottom - panelRect.top, true);
		return;
	}
	RECT* pExtendRext = (RECT*)GetMember(L"ExtendRext");
	RECT ExtendRext = { 0 };
	if (pExtendRext != 0)
		CopyMemory(&ExtendRext, pExtendRext, sizeof(RECT));
	bool hasCommonV6 = !LoadAndCheckManifest(zyEnv::getInstance().getHandle());
	int style = (int)GetWindowLongPtr(hWndTab, GWL_STYLE);
	RECT itemRect = { 0 };
	if ((style & TCS_VERTICAL) == 0) {
		if ((style & TCS_BOTTOM) == 0) {
			SendMessage(hWndTab, TCM_GETITEMRECT, lastIndex, (LPARAM)&itemRect);
			if (hasCommonV6)
				panelRect = { ExtendRext.left , itemRect.bottom + ExtendRext.top, tabRect.right + ExtendRext.right - 2, tabRect.bottom + ExtendRext.bottom - 1 };
			else
				panelRect = { ExtendRext.left, itemRect.bottom + ExtendRext.top, tabRect.right + ExtendRext.right - 1, tabRect.bottom + ExtendRext.bottom - 1 };
		}
		else {
			SendMessage(hWndTab, TCM_GETITEMRECT, 0, (LPARAM)&itemRect);

			if (hasCommonV6) {
				panelRect = { ExtendRext.left - 1, ExtendRext.top - 2, tabRect.right + ExtendRext.right - 2, itemRect.top + ExtendRext.bottom - 1 };
			}
			else
				panelRect = { ExtendRext.left, ExtendRext.top - 5, tabRect.right + ExtendRext.right - 1, itemRect.top + ExtendRext.bottom - 1 };
		}
	}
	else {
		if ((style & TCS_RIGHT) == 0) {
			SendMessage(hWndTab, TCM_GETITEMRECT, lastIndex, (LPARAM)&itemRect);
			if (hasCommonV6)
				panelRect = { itemRect.right + ExtendRext.top, ExtendRext.top, tabRect.right + ExtendRext.right - 2, tabRect.bottom + ExtendRext.bottom - 1 };
			else
				panelRect = { itemRect.right + ExtendRext.top, ExtendRext.top, tabRect.right + ExtendRext.right - 1, tabRect.bottom + ExtendRext.bottom - 1 };
		}
		else {
			SendMessage(hWndTab, TCM_GETITEMRECT, 0, (LPARAM)&itemRect);
			if (hasCommonV6)
				panelRect = { ExtendRext.left, ExtendRext.top, itemRect.left + ExtendRext.right, tabRect.bottom + ExtendRext.bottom };
			else
				panelRect = { ExtendRext.left, ExtendRext.top, itemRect.left + ExtendRext.right - 1, tabRect.bottom + ExtendRext.bottom - 1 };
		}
	}
	MoveWindow(hWnd, panelRect.left, panelRect.top, panelRect.right - panelRect.left, panelRect.bottom - panelRect.top, true);
}

void BlackMoonUI::zyTabControl::SetPanelsSize(HWND hWndTab)
{
	int count = (int)SendMessage(hWndTab, TCM_GETITEMCOUNT, 0, 0);
	TCITEM tci = { 0 };
	tci.mask = TCIF_PARAM;
	for (int i = 0; i < count; i++) {
		tci.lParam = 0;
		SendMessage(hWndTab, TCM_GETITEMW, i, (LPARAM)&tci);
		SetPanelSize(hWndTab, tci.lParam);
	}
}

bool BlackMoonUI::zyTabControl::DeleteAllPanel(HWND hWndTab)
{
	int count = (int)SendMessage(hWndTab, TCM_GETITEMCOUNT, 0, 0);
	if (count == 0)
		return false;
	TCITEM tci = { 0 };
	tci.mask = TCIF_PARAM;
	for (int i = 0; i < count; i++) {
		SendMessage(hWndTab, TCM_GETITEMW, i, (LPARAM)&tci);
		zyWindow* panel = reinterpret_cast<zyWindow*>(tci.lParam);
		if (panel != nullptr && panel->getHwnd() != 0) {
			// 发送 WM_CLOSE 消息给面板的窗口句柄  
			SendMessage(panel->getHwnd(), WM_CLOSE, 0, 0);
			//DeletePanel(panel);
			//delete panel;
		}
		LONG_PTR HashToolTips = GetMember(L"HashToolTips");
		if (HashToolTips != NULL) {
			std::unordered_map<LPARAM, std::wstring>* ToolTips = reinterpret_cast<std::unordered_map<LPARAM, std::wstring>*>(HashToolTips);
			auto it = ToolTips->find(tci.lParam);
			if (it != ToolTips->end()) {
				ToolTips->erase(it);
			}
		}
	}
	return SendMessage(hWndTab, TCM_DELETEALLITEMS, 0, 0) != 0;
}

void BlackMoonUI::zyTabControl::DeletePanel(zyWindow* 参数_面板)
{
	if (参数_面板 != nullptr) {
		HWND hwndPanel = 参数_面板->getHwnd();
		SendMessage(hwndPanel, WM_CLOSE, 0, 0);
		delete 参数_面板;
	}
}
BOOL BlackMoonUI::zyTabControl::创建(HWND 参数_父窗口, const std::wstring& 参数_标题, POINT 参数_位置, POINT 参数_尺寸, int 参数_ID, int 参数_窗口风格, int 参数_扩展风格)
{
	if (参数_窗口风格 == 0)
		参数_窗口风格 = TCS_TOOLTIPS;
	if (参数_ID == NULL)
		参数_ID = 黑月默认ID();
	BOOL ret = _CreateCtrol(参数_父窗口, 参数_标题, 参数_位置, 参数_尺寸, 参数_ID, 参数_窗口风格 | WS_CLIPCHILDREN, 参数_扩展风格 | WS_EX_CONTROLPARENT, L"SysTabControl32");
	if (ret) {
		RECT* ExtendRext = new(RECT);
		ExtendRext->left = 2;
		ExtendRext->top = 3;
		ExtendRext->right = -1;
		ExtendRext->bottom = -1;
		SetMember(L"ExtendRext", (LONG_PTR)ExtendRext);
	}
	return ret;
}

BOOL BlackMoonUI::zyTabControl::创建(zyWindow& 参数_父窗口, const std::wstring& 参数_标题, POINT 参数_位置, POINT 参数_尺寸, int 参数_ID, int 参数_窗口风格, int 参数_扩展风格)
{
	if (参数_窗口风格 == 0)
		参数_窗口风格 = TCS_TOOLTIPS;
	if (参数_ID == NULL)
		参数_ID = 黑月默认ID();
	BOOL ret = _CreateCtrol(参数_父窗口.getHwnd(), 参数_标题, 参数_位置, 参数_尺寸, 参数_ID, 参数_窗口风格 | WS_CLIPCHILDREN, 参数_扩展风格 | WS_EX_CONTROLPARENT, L"SysTabControl32");
	if (ret) {
		RECT* ExtendRext = new(RECT);
		ExtendRext->left = 2;
		ExtendRext->top = 3;
		ExtendRext->right = -1;
		ExtendRext->bottom = -1;
		SetMember(L"ExtendRext", (LONG_PTR)ExtendRext);
	}
	return ret;
}
int BlackMoonUI::zyTabControl::插入子夹(zyWindow* 参数_面板, int 参数_子夹索引, const std::wstring& 参数_子夹名称, int 参数_图片索引, const std::wstring& 参数_提示文本) {
	if (参数_子夹索引 == -1)
		参数_子夹索引 = (int)sendMsg(TCM_GETITEMCOUNT, 0, 0);
	TCITEM tci = { 0 };
	tci.mask = TCIF_PARAM;
	if (!参数_子夹名称.empty())
		tci.mask |= TCIF_TEXT;
	if (参数_图片索引 > -1)
		tci.mask |= TCIF_IMAGE;
	tci.pszText = (LPWSTR)参数_子夹名称.c_str();
	tci.cchTextMax = (int)参数_子夹名称.size();
	tci.iImage = 参数_图片索引;
	if (参数_面板) {
		tci.lParam = (LPARAM)参数_面板;
		参数_面板->setParent(取窗口句柄());
		参数_面板->SetMember(L"TabPanel", 1);
	}
	else {
		zyPanel* p = new zyPanel();
		HWND hParent = 取窗口句柄();
		if (p->创建(hParent, L"", POINT{ -1, -1 }, POINT{ 200, 200 })) {
			tci.lParam = (LPARAM)(zyWindow*)p;
			p->setParent(hParent);
			//std::wcout << p->getHwnd() << std::endl;
			//p->SetMember(L"hWnd", (LONG_PTR)p->getHwnd());
			p->SetMember(L"TabPanel", 1);
		}
	}
	int ret = (int)sendMsg(TCM_INSERTITEMW, 参数_子夹索引, (LPARAM)&tci);
	if (ret == -1)
		return (ret);
	LONG_PTR HashToolTips = GetMember(L"HashToolTips");
	if (HashToolTips != NULL && !参数_提示文本.empty()) {
		std::unordered_map<LPARAM, std::wstring>* ToolTips = (std::unordered_map<LPARAM, std::wstring>*)HashToolTips;
		//ToolTips[tci.lParam] = 参数_提示文本;
		ToolTips->insert_or_assign(tci.lParam, 参数_提示文本);
	}
		
	SetPanelSize(取窗口句柄(), tci.lParam);
	ShowPanel(取窗口句柄(), (int)sendMsg(TCM_GETCURSEL, 0, 0));
	return (ret);
}
int BlackMoonUI::zyTabControl::添加子夹(zyWindow* 参数_面板, const std::wstring& 参数_子夹名称, int 参数_图片索引, const std::wstring& 参数_提示文本) {//返回子夹的索引。
	int index = (int)sendMsg(TCM_GETITEMCOUNT, 0, 0);
	return 插入子夹(参数_面板, index, 参数_子夹名称, 参数_图片索引, 参数_提示文本);
}
int BlackMoonUI::zyTabControl::取子夹数() {
	return (int)SendMessage(getHwnd(), TCM_GETITEMCOUNT, 0, 0);
}
HWND BlackMoonUI::zyTabControl::取面板句柄(int 参数_子夹索引) {
	TCITEM tci = { 0 };
	tci.mask = TCIF_PARAM;
	int ret = (int)sendMsg(TCM_GETITEMW, 参数_子夹索引, (LPARAM)&tci);
	if (ret == 0 || tci.lParam == 0)
		return 0;
	return ((zyWindow*)tci.lParam)->getHwnd();
}
bool BlackMoonUI::zyTabControl::绑定(HWND 参数_父窗口, int 参数_资源ID, bool 参数_使用默认字体) {//成功返回真，失败返回假。

	HWND hwnd = GetDlgItem(参数_父窗口, 参数_资源ID);
	if (IsWindow(hwnd) != 0) {
		int exStyle = (int)GetWindowLongPtr(hwnd, GWL_EXSTYLE);
		SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle | WS_EX_CONTROLPARENT);
		if (参数_使用默认字体)
			SendMessage(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
	}
	if (_BindWindow(hwnd)) {
		RECT* ExtendRext = new(RECT);
		ExtendRext->left = 2;
		ExtendRext->top = 3;
		ExtendRext->right = -1;
		ExtendRext->bottom = -1;
		SetMember(L"ExtendRext", (LONG_PTR)ExtendRext);
		return true;
	}
	return false;
}
bool BlackMoonUI::zyTabControl::绑定窗口句柄(HWND 参数_窗口句柄) {
	if (_BindWindow(参数_窗口句柄)) {
		int exStyle = (int)GetWindowLongPtr(参数_窗口句柄, GWL_EXSTYLE);
		SetWindowLongPtr(参数_窗口句柄, GWL_EXSTYLE, exStyle | WS_EX_CONTROLPARENT);
		RECT* ExtendRext = new(RECT);
		ExtendRext->left = 2;
		ExtendRext->top = 3;
		ExtendRext->right = -1;
		ExtendRext->bottom = -1;
		SetMember(L"ExtendRext", (LONG_PTR)ExtendRext);
		return true;
	}
	return false;
}
int BlackMoonUI::zyTabControl::取子夹行数() {//当子夹允许多行时，取出子夹的行数。
	return (int)sendMsg(TCM_GETROWCOUNT, 0, 0);
}
RECT BlackMoonUI::zyTabControl::取子夹矩形(int 参数_子夹索引) {
	RECT 局部_矩形 = { 0 };
	sendMsg(TCM_GETITEMRECT, 参数_子夹索引, (LPARAM)&局部_矩形);
	return 局部_矩形;
}
std::wstring BlackMoonUI::zyTabControl::取子夹名称(int 参数_子夹索引) {
	TCITEM tci = { 0 };
	std::wstring wText;
	tci.mask = TCIF_TEXT;
	wText.reserve(520);
	tci.pszText = (LPWSTR)wText.c_str();
	tci.cchTextMax = 520;
	sendMsg(TCM_GETITEMW, 参数_子夹索引, (LPARAM)&tci);
	return wText;
}
bool BlackMoonUI::zyTabControl::置子夹名称(int 参数_子夹索引, const std::wstring& 参数_子夹名称) {//成功返回真，失败返回假。
	TCITEM tci = { 0 };
	tci.mask = TCIF_TEXT;
	tci.pszText = (LPWSTR)参数_子夹名称.c_str();
	tci.cchTextMax = (int)参数_子夹名称.size();
	int ret = (int)sendMsg(TCM_SETITEMW, 参数_子夹索引, (LPARAM)&tci);
	return ret != 0;
}
bool BlackMoonUI::zyTabControl::置提示文本(int 参数_子夹索引, const std::wstring& 参数_提示文本) {//成功返回真，失败返回假。必须有 选择夹_工具提示 风格
	TCITEM tci = { 0 };
	tci.mask = TCIF_PARAM;
	int ret = (int)sendMsg(TCM_GETITEMW, 参数_子夹索引, (LPARAM)&tci);
	if (ret == 0 || tci.lParam == 0)
		return false;
	LONG_PTR HashToolTips = GetMember(L"HashToolTips");
	if (HashToolTips != NULL && !参数_提示文本.empty()) {
		std::unordered_map<LPARAM, std::wstring>* ToolTips = (std::unordered_map<LPARAM, std::wstring>*)HashToolTips;
		//ToolTips[tci.lParam] = 参数_提示文本;
		ToolTips->insert_or_assign(tci.lParam, 参数_提示文本);
		return true;
	}
	return false;
}
std::wstring BlackMoonUI::zyTabControl::取提示文本(int 参数_子夹索引) {//必须有 选择夹_工具提示 风格
	TCITEM tci = { 0 };
	tci.mask = TCIF_PARAM;
	int ret = (int)sendMsg(TCM_GETITEMW, 参数_子夹索引, (LPARAM)&tci);
	if (ret == 0 || tci.lParam == 0)
		return L"";
	std::unordered_map<LPARAM, std::wstring>* ToolTips = reinterpret_cast<std::unordered_map<LPARAM, std::wstring>*>(GetMember(L"HashToolTips"));
	auto it = ToolTips->find(tci.lParam);
	if (it != ToolTips->end()) {
		return it->second;
	}
	return L"";
}
int BlackMoonUI::zyTabControl::取子夹图片(int 参数_子夹索引) {//返回图片索引。
	TCITEM tci = { 0 };
	tci.mask = TCIF_IMAGE;
	sendMsg(TCM_GETITEMW, 参数_子夹索引, (LPARAM)&tci);
	return tci.iImage;
}
bool BlackMoonUI::zyTabControl::置子夹图片(int 参数_子夹索引, int 参数_图片索引) {//成功返回真，失败返回假。
	TCITEM tci = { 0 };
	tci.mask = TCIF_IMAGE;
	tci.iImage = 参数_图片索引;
	int ret = (int)sendMsg(TCM_SETITEMW, 参数_子夹索引, (LPARAM)&tci);
	return ret != 0;
}
bool BlackMoonUI::zyTabControl::清空() {//成功返回真，失败返回假。
	return DeleteAllPanel(取窗口句柄());
}
bool BlackMoonUI::zyTabControl::删除子夹(int 参数_子夹索引) {//成功返回真，失败返回假。
	TCITEM tci = { 0 };
	int curentItem = (int)sendMsg(TCM_GETCURSEL, 0, 0);
	if (curentItem == -1)
		curentItem = 0;
	tci.mask = TCIF_PARAM;
	int ret = (int)sendMsg(TCM_GETITEMW, 参数_子夹索引, (LPARAM)&tci);
	if (ret == 0)
		return false;
	ret = (int)sendMsg(TCM_DELETEITEM, 参数_子夹索引, 0);
	if (ret == 0)
		return true;
	LONG_PTR HashToolTips = GetMember(L"HashToolTips");
	if (HashToolTips != 0) {
		std::unordered_map<LPARAM, std::wstring>* ToolTips = reinterpret_cast<std::unordered_map<LPARAM, std::wstring>*>(HashToolTips);
		auto it = ToolTips->find(tci.lParam);
		if (it != ToolTips->end()) {
			ToolTips->erase(it);
		}
	}
	DeletePanel((zyWindow*)tci.lParam);
	int count = (int)sendMsg(TCM_GETITEMCOUNT, 0, 0);
	if (curentItem == 参数_子夹索引) {
		if (curentItem == count)
			curentItem = curentItem - 1;
		置现行选中子夹(curentItem);
	}
	return true;
}
int BlackMoonUI::zyTabControl::取现行选中子夹() {//返回子夹索引
	return (int)sendMsg(TCM_GETCURSEL, 0, 0);
}
void BlackMoonUI::zyTabControl::置现行选中子夹(int 参数_子夹索引) {
	NMHDR nm = { 0 };
	HWND hwnd = 取窗口句柄();
	nm.hwndFrom = hwnd;
	nm.idFrom = GetWindowLongPtr(hwnd, GWL_ID);
	nm.code = TCN_SELCHANGING;
	SendMessage(GetParent(nm.hwndFrom), WM_NOTIFY, 0, (LPARAM)&nm);
	sendMsg(TCM_SETCURSEL, 参数_子夹索引, 0);
	nm.code = TCN_SELCHANGE;
	SendMessage(GetParent(nm.hwndFrom), WM_NOTIFY, 0, (LPARAM)&nm);
}
bool BlackMoonUI::zyTabControl::高亮子夹(int 参数_子夹索引, bool 参数_是否高亮) {//成功返回真，失败返回假。
	return sendMsg(TCM_HIGHLIGHTITEM, 参数_子夹索引, 参数_是否高亮 ? 1 : 0) != 0;
}
int BlackMoonUI::zyTabControl::取坐标子夹(int 参数_横坐标, int 参数_纵坐标) {//成功返回子夹索引，失败返回-1。
	TCHITTESTINFO 局部_信息 = { 0 };
	局部_信息.pt.x = 参数_横坐标;
	局部_信息.pt.y = 参数_纵坐标;
	局部_信息.flags = TCHT_ONITEM;
	return (int)sendMsg(TCM_HITTEST, 0, (LPARAM)&局部_信息);
}
int BlackMoonUI::zyTabControl::置子夹头尺寸(int 参数_宽度, int 参数_高度) {//返回之前的大小，低16为代表宽度，高16代表高度。如果选择夹包含"选择夹_固定宽度"风格才能设置宽度
	int ret = (int)sendMsg(TCM_SETITEMSIZE, 0, MAKELPARAM(参数_宽度, 参数_高度));
	SetPanelsSize(取窗口句柄());
	return ret;
}
BlackMoonUI::zyLmageList BlackMoonUI::zyTabControl::取图片组() {
	// 获取当前设置的图片组对象
	resObject *pImageList = reinterpret_cast<resObject*>(GetMember(L"pImageList"));
	if (pImageList != nullptr) {
		zyLmageList imagelist;
		imagelist.setObject(pImageList);
		return imagelist;
	}
	zyLmageList newimagelist ;
	HIMAGELIST himl = (HIMAGELIST)sendMsg(TCM_GETIMAGELIST, 0, 0);
	newimagelist.置句柄(himl);
	resObject* res = newimagelist.getObject();
	res->addRef();
	//IUnknown_AddRef (pImageList)
	SetMember(L"pImageList", (LONG_PTR)res);
	return newimagelist;
}
void BlackMoonUI::zyTabControl::置图片组(zyLmageList& 参数_图片组) {
	resObject* pImageList = reinterpret_cast<resObject*>(GetMember(L"pImageList"));
	if (pImageList != nullptr)
		pImageList->release();
	pImageList = 参数_图片组.getObject();
	pImageList->addRef();
	//IUnknown_AddRef (pImageList)
	SetMember(L"pImageList", (LONG_PTR)pImageList);
	sendMsg(TCM_SETIMAGELIST, 0, (LPARAM)参数_图片组.取句柄());
}
int BlackMoonUI::zyTabControl::置选择夹扩展风格(int 参数_选择夹扩展风格) { 
	return (int)sendMsg(TCM_SETEXTENDEDSTYLE, 0, 参数_选择夹扩展风格); 
}
int BlackMoonUI::zyTabControl::取选择夹扩展风格() { 
	return (int)sendMsg(TCM_GETEXTENDEDSTYLE, 0, 0); 
}
int BlackMoonUI::zyTabControl::置子夹最小宽度(int 参数_最小宽度) { 
	return (int)sendMsg(TCM_SETMINTABWIDTH, 0, 参数_最小宽度); 
}
void BlackMoonUI::zyTabControl::置子夹内边距(int 参数_水平边距, int 参数_垂直边距) {
	sendMsg(TCM_SETPADDING, 0, MAKELPARAM(参数_水平边距, 参数_垂直边距));
}
bool BlackMoonUI::zyTabControl::隐藏自身(bool 参数_隐藏自身) {
	SetMember(L"HideSelf", 参数_隐藏自身);
	SetPanelsSize(取窗口句柄());
	重画();
	return 参数_隐藏自身;
}
bool BlackMoonUI::zyTabControl::隐藏自身() {
	return GetMember(L"HideSelf") != 0;
}
BlackMoonUI::zyWindow* BlackMoonUI::zyTabControl::取面板(int 参数_子夹索引) {//获取指定子夹的面板窗口
	TCITEM tci = { 0 };
	tci.mask = TCIF_PARAM;
	int ret = (int)sendMsg(TCM_GETITEMW, 参数_子夹索引, (LPARAM)&tci);
	if (ret == 0)
		return nullptr;
	zyWindow* p = reinterpret_cast<zyWindow*>(tci.lParam);
	if (!p) // 添加空指针检查
		return nullptr;
	//参数_面板 = *p;
	//参数_面板.setObject(p->getObject());
	//参数_面板.置窗口句柄(p->取窗口句柄());
	return p;
}
void BlackMoonUI::zyTabControl::置面板边缘扩展(RECT& 参数_边缘扩展) {//设置面板的上下左右扩展距离
	RECT* pExtendRext = (RECT*)GetMember(L"ExtendRext");
	if (pExtendRext != 0) {
		pExtendRext->left = 参数_边缘扩展.left;
		pExtendRext->top = 参数_边缘扩展.top;
		pExtendRext->right = 参数_边缘扩展.right;
		pExtendRext->bottom = 参数_边缘扩展.bottom;
		SetMember(L"ExtendRext", (LONG_PTR)pExtendRext);
	}
}
void BlackMoonUI::zyTabControl::重置面板尺寸() { SetPanelsSize(取窗口句柄()); }
//@备注 函数 整型 OnClick(HWND hWnd)
void BlackMoonUI::zyTabControl::事件_被单击(TRegEvent* 参数_事件指针) { SetRegEvent(L"OnClick", 参数_事件指针); }
//@备注 函数 整型 OnRClick(HWND hWnd)
void BlackMoonUI::zyTabControl::事件_右键单击(TRegEvent* 参数_事件指针) { SetRegEvent(L"OnRClick", 参数_事件指针); }
//@备注 函数 整型 OnSelChange(HWND hWnd)
void BlackMoonUI::zyTabControl::事件_子夹被改变(TRegEvent* 参数_事件指针) { SetRegEvent(L"OnSelChange", 参数_事件指针); }
//@备注 返回值：整型【非0禁止改变，0允许改变】 函数 整型 OnSelChanging(HWND hWnd)
void BlackMoonUI::zyTabControl::事件_将改变子夹(TRegEvent* 参数_事件指针) { SetRegEvent(L"OnSelChanging", 参数_事件指针); }